//qq群主
var weiAccountQqGroupLeader = {
	//请求url
	listUrl:"/weiAccountQqGroupLeader/list.action", //列表地址
	toAddUrl:"/weiAccountQqGroupLeader/toAdd.action", //去添加页面地址
	addUrl:"/weiAccountQqGroupLeader/add.action", //添加地址
	toEditUrl:"/weiAccountQqGroupLeader/toEdit.action?id=", //去修改页面地址
	editUrl:"/weiAccountQqGroupLeader/edit.action", //去修改页面地址
	deleteUrl :"/weiAccountQqGroupLeader/delete.action?id=", //删除页面地址
	toViewUrl:"/weiAccountQqGroupLeader/toView.action?id=", //详细页面地址
	getByIdUrl : "/weiAccountQqGroupLeader/getById.action", //根据id查询对象
	modifyDeleteStatusUrl:"/weiAccountQqGroupLeader/modifyDeleteStatus.action", //停用 或启用
	checkNameExitsUrl : "/weiAccountQqGroupLeader/checkNameExits.action", //检验唯一性,
	cancleCooperationUrl : "/weiAccountQqGroupLeader/cancleCooperation.action", //取消合作,
	agreeCooperationUrl : "/weiAccountQqGroupLeader/agreeCooperation.action",//同意合作
	complainWeiUrl : "/weiAccountQqGroupLeader/complainWei.action",//同意合作
	left_menu_selected_id : "weiaccountqqgroupleader_id",//左侧选中ID
	recommendFlowListUrl: "/zpRecommendFlowInfo/leaderList.action?qqGroupNumber=",//推荐流程列表
	

	onlyName :  $("#onlyName"), //修改，唯一验证时需要添加此属性
	m_title : $(".m_title"),//页面标题
	_title_val : "qq群主",
	
	addform : jQuery("#addform"), //添加form
	queryfrom :jQuery("#queryForm"), //查询form
	addBtn : $("#addBtn"),//添加按钮
	queryBtn : $("#queryBtn"),//查询按钮
	left_menu_selected_id : "weiAccountQqGroupLeader_list",   //左侧菜单选择id  
	cancelForm : $("#cancelForm"),//拒绝合作form
	groupId :  $("#groupId"),//群
	leaderCooperationEndFeedback :  $("#leaderCooperationEndFeedback"),//原因

	//属性
	
	id : $("#id"), //id
	accountId : $("#accountId"), //所属账户id
	groupId : $("#groupId"), //所属群
	inTime : $("#inTime"), //录入时间
	inPerson : $("#inPerson"), //录入人
	updateTime : $("#updateTime"), //更新时间
	isDelete : $("#isDelete"), //是否删除
	inPersonName : $("#inPersonName"),
	//页面初始化
	initPage : function (){
		var self = this;
		self.currPage = common.getCurrPageFlag();
		common.initLeftMenuSelected(self.left_menu_selected_id);

		//初始化标题
		common.initPageTitle(self._title_val,self.m_title);
		//列表页面
		if(self.currPage!="list"){
			self.addform.validationEngine({scroll:false});
			self.addBtn.unbind("click").click(function(){
				self.add();
			});
		}
		if(self.currPage=="list"){
			self.initSeletePage();
		}else
		if(self.currPage=="edit"){
			self.initEditPage();
		} else 
		if(self.currPage=="add"){
			self.initAddPage();
		}else 
		if(self.currPage=="detail"){
			self.initDetailPage();
		}
	},
	initSeletePage : function (){
		var self =this;
		//self.queryfrom.validationEngine({scroll:false});
		self.queryBtn.unbind("click").click(function(){
			self.query();
		});
    },
	//列表查询

	//初始化添加页面
	initAddPage : function (){
		var self = this;
		self.addform.attr("action",self.addUrl);
		//检验名称唯一性
		/*self.name.blur(function(){
				if($.trim(this.value).length>0){
					var param = {flag : common.getCurrPageFlag(),name:this.value};
					self.checkNameExits(param,self.checkNameExitCallBack);
				} 
		});*/
		
		
	},
	
	
	//qq群主 添加 
	add : function (){
			var self = this;
			var b = self.addform.validationEngine('validate');
			if(!b){
				return false;
			}
			//$("#desc").val(CKEDITOR.instances.desc1.getData());
			//$("#moreDesc").val(CKEDITOR.instances.desc2.getData());
			if(self.currPage=="edit"){
				   common.openModal("delete_sure","确定修改信息吗？");
				   $("#delete_sure_a").unbind("click").click(function(){
					   self.ajaxSubmitForm();
				   });
			} else {
					self.ajaxSubmitForm();
		    }
	},

	//初始化修改页面数据
	initEditPage : function (){
		var self = this;
		self.getById(this.updateTime.val(),function (result){
			if (result.s > 0) {
				self.setForm(result.data);
			}//不存在
			else if (result.s==-1000) {
				location.href = common.notFindUrl;
			}  
			else {
				common.alert(resp.d);
			}
		});
		self.addform.attr("action",self.editUrl);
		//检验名称唯一性
		/*self.name.blur(function(){
				if($.trim(this.value).length>0){
					var param = {flag : common.getCurrPageFlag(),name:this.value,oldname:self.onlyName.val()};
					self.checkNameExits(param,self.checkNameExitCallBack);
				} 
		});*/
   },
   
   //更新删除状态
   modifyDeleteStatus : function (id,status){
	   var self = this;
	   var delTitle = "";
	   if(status==1){
		   status=2;
		   delTitle="确定暂停吗?";
	   } else 
	   if(status==2){
		   status=1;
		   delTitle="确定启用吗？";
	   }	   
	   common.openModal("delete_sure",delTitle);
	   $("#delete_sure_a").unbind("click").click(function(){
		  location.href= self.modifyDeleteStatusUrl+"?id="+id+"&deleteStatus="+status; 
	   });
   },
   //拒绝合作
   rejectWei : function (id){
	   var self = this;
		
		$("#tt_sure").modal().css({
			'margin-top': function () {
		        return -($(this).height()/2)},
		    'margin-left': function () {
		        return -($(this).width()/2);
		    }
		});
	  $(".ke-container-default").css({"width":"475px"});
	  if(self.editor){
      	self.editor.remove();
      }
		self.editor = KindEditor.create('textarea[name="tt_leaderCooperationEndFeedback"]',{
		//allowPreviewEmoticons : false,
		 uploadJson : '/file/kindEditorUplad.action', //上传
		 fileManagerJson : 'file_manager.do', // 文件管理
		 allowFileManager : true,
		items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
	   
		$("#leaderCooperationEnd_a").unbind("click").click(function(){
			   if(self.editor.isEmpty()){
					common.alert("内容不允许为空!");
					return;
				}
			  $.post(
					  self.cancleCooperationUrl,
					  {id:id,leaderCooperationEndFeedback:self.editor.html() },
					  function(result){
						  if(result.s==1){
							  location.reload();
						  }else{
							  common.alert(result.d);
						  }
						  }
					  );
		 });
	   
		   
   },
 //投诉微用户
   complainWei : function (groupId){
	   var self = this;
		$("#complain_sure").modal().css({
			'margin-top': function () {
		        return -($(this).height()/2)},
		    'margin-left': function () {
		        return -($(this).width()/2);
		    }
		});
		if(self.editor){
        	self.editor.remove();
        }
		self.editor = KindEditor.create('textarea[name="complainEndFeedback"]',{
		//allowPreviewEmoticons : false,
		 uploadJson : '/file/kindEditorUplad.action', //上传
		 fileManagerJson : 'file_manager.do', // 文件管理
		 allowFileManager : true,
		items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
		$("#complainEnd_a").unbind("click").click(function(){
			   if(self.editor.isEmpty()){
					common.alert("内容不允许为空!");
					return;
				}
			 $.post(
					  self.complainWeiUrl,
					  {content:self.editor.html(),
						  groupId:  groupId
					  },
					  function(result){
						  if(result.s==1){
							  location.reload();
						  }else{
							  common.alert(result.d);
						  }
						  }
					  );
		 });
	   
		   
   },
   //填充表单数据
   setForm : function (obj){
	   var self = this;
	    //唯一验证时需要记录原来的名称
	   self.onlyName.val(obj.name);
	   //赋值
		$("input[name='id'][value='"+obj.id+"']").attr("checked",true); //id
		$("input[name='accountId'][value='"+obj.accountId+"']").attr("checked",true); //所属账户id
		$("input[name='groupId'][value='"+obj.groupId+"']").attr("checked",true); //所属群
		if(obj.inTime && obj.inTime>0){
		  var new1 = new Date(obj.inTime).format("yyyy-MM-dd HH:mm");
		  self.inTime.html(new1); //录入时间
		}
			
		//其它属性
		self.inPerson.html(obj.inPerson);
			
		//其它属性
		self.updateTime.val(obj.updateTime); //更新时间
		
		//用户详情显示信息
                //启用状态
		if(obj.isDelete && obj.isDelete==1){
			self.isDelete.html("启用");
        	}else
    	 //停用状态
		if(obj.isDelete && obj.isDelete==2){
			self.isDelete.html("暂停");
			}
			
		//其它属性
		self.inPersonName.html(obj.inPersonName);
   },
   toComplainInfo : function (){
		var win_w = $(window).width();
		var win_h = $(window).height();
		var self = this;
		
		self.suggestModal = $("#"+self.suggestModalId); 
		$.post(self.toAddUrl, function(doc) {
			self.suggestModal.html(doc);
			self.suggestModal.modal().css({
				  'width':win_w*0.6,
				  'height':win_h*0.8,
				  'margin':'0px',
		             'top':(win_h-win_h*0.8)/2 + "px" ,	
		             'left':(win_w-win_w*0.6)/2 + "px" ,
		           // 'margin-left': function () {
		            	// return -($(this).width()/2);
		            // }
			}
			
		);
			//self.initAdd();
		});
	},
	
	testa : function(){
		var self = this;
		
		$("#tt_sure").modal().css({
			'margin-top': function () {
		        return -($(this).height()/2)},
		    'margin-left': function () {
		        return -($(this).width()/2);
		    }
		});
	  $(".ke-container-default").css({"width":"475px"});
	  if(self.editor){
      	self.editor.remove();
      }
		self.editor = KindEditor.create('textarea[name="tt_content_edit"]',{
		//allowPreviewEmoticons : false,
		 uploadJson : '/file/kindEditorUplad.action', //上传
		 fileManagerJson : 'file_manager.do', // 文件管理
		 allowFileManager : true,
		items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
	},
	agreeCoopertion : function(id,groupNum,groupName){	
	var self =this;
	$("#group_num").html(groupNum);
	$("#group_name").html(groupName);
	common.openModal("agreeCoope");
	$("#agree_confirm").unbind("click").click(function(){
		  $.post(
				  self.agreeCooperationUrl,
				  {id:id},
				  function(result){
					  if(result.s==1){
						  location.reload();
					  }else{
						  common.alert(result.d);
					  }
					  }
				  );
		  location.reload();
		});
	},
	scanResumeProcess : function(groupNumber){
		location.href = this.recommendFlowListUrl + groupNumber;
	}
}
//每个继承base.js的原js中 扩展当前对方法

weiAccountQqGroupLeader = jQuery.extend(null,weiAccountQqGroupLeader,base, null);